package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.conn.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;


    //根据userId查询用户信息
    @GetMapping("/getUserInfoById/{userId}")
    public Result<UserInfo> getUserInfoById(@PathVariable Long userId) {
        UserInfo userInfo = userInfoService.getUserInfoById(userId);
        return Result.ok(userInfo);
    }

    @GetMapping(value = "/findUserInfoVoByUserId/{userId}")
    public Result<UserInfoVo> findUserInfoVoByUserId(@PathVariable Long userId) {
        UserInfoVo userInfoVo = userInfoService.findUserInfoVoByUserId(userId);
        return Result.ok(userInfoVo);
    }


    //判断用户是否购买声音列表
    @GuiGuLogin
    @PostMapping("userIsPaidAlbumAndTrack/{albumId}")
    public Result<Map<Long, Integer>> userIsPaidAlbumAndTrack(@PathVariable("albumId") Long albumId,
                                                              @RequestBody List<Long> trackIds) {
        Map<Long, Integer> map = userInfoService.userIsPaidAlbumAndTrack(albumId, trackIds);
        return Result.ok(map);
    }

    //判断用户是否购买过专辑
    @GetMapping("isPaidAlbum/{albumId}")
    @GuiGuLogin
    public Result<Boolean> isPaidAlbum(@PathVariable("albumId") Long albumId) {
        Boolean isPaidAlbum = userInfoService.isPaidAlbum(albumId);
        return Result.ok(isPaidAlbum);
    }

    //远程调用:根据专辑id获取用户支付过的声音id列表
    @GuiGuLogin
    @GetMapping("findUserPaidTrackList/{albumId}")
    public Result<List<Long>> findUserPaidTrackList(@PathVariable Long albumId){
       List<Long> trackIds = userInfoService.findUserPaidTrackList(albumId);
       return Result.ok(trackIds);
    }
}

